package com.sms.connection;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;


public class HibernateUtil {

	public HibernateUtil() {
		super();
	}

	public static final SessionFactory sessionFactory;

	static {
		try {
			System.out.println("in HibernateUtil");
			
//			URL url = Thread.currentThread().getContextClassLoader().getResource("com/pbd/connection/hibernate.cfg.xml"); 
//			Configuration cfg = new Configuration();
			
//			cfg.setProperty("hibernate.dialect","org.hibernate.dialect.MySQLDialect");
//			cfg.setProperty("hibernate.connection.url","jdbc:mysql://localhost/pbd");
//			cfg.setProperty("hibernate.connection.username", "root");
//			cfg.setProperty("hibernate.connection.driver_class","com.mysql.jdbc.Driver");
//			cfg.setProperty("hibernate.connection.password", "root123");
//			cfg.setProperty("hibernate.transaction.factory_class","org.hibernate.transaction.JDBCTransactionFactory");
//			cfg.setProperty("hibernate.current_session_context_class","thread");
//			cfg.setProperty("hibernate.show_sql", "true");
//			cfg.addPackage("com.pbd.shared");
//			cfg.addAnnotatedClass(com.pbd.shared.PARTYCONTACT.class);
//			cfg.addAnnotatedClass(com.pbd.shared.PARTY.class);
//			cfg.addAnnotatedClass(com.pbd.shared.LEADMASTER.class);
//			cfg.addAnnotatedClass(com.pbd.shared.CORRESPONDENCEDETAIL.class);
//			cfg.addAnnotatedClass(com.pbd.shared.BUSINESSCATEGORY.class);
//			cfg.addAnnotatedClass(com.pbd.shared.BUSINESSCATEGORYRELATION.class);
//			cfg.addAnnotatedClass(com.pbd.shared.ALBUMMASTER.class);
//			cfg.addAnnotatedClass(com.pbd.shared.MEDIARELATION.class);
//			cfg.addAnnotatedClass(com.pbd.shared.AREA.class);
//			
//			sessionFactory = new Configuration().configure().buildSessionFactory();
			Configuration configuration = new Configuration();
		    configuration.configure();
		    
		    
//		    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().configure().buildServiceRegistry();
//		    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
//		    sessionFactory = metadataSources.buildMetadata().buildSessionFactory();
//		    
		    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        
		    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
		} catch (Throwable ex) {
			ex.printStackTrace();
			throw new ExceptionInInitializerError(ex);
		}
	}
	int a;
	float f1;

	
	public static void main(String args[]) {
		sessionFactory.getAllClassMetadata();
	}

	
	}